package com.cgbl.cg.adapter

import com.cgbl.cg.R
import com.cgbl.cg.utils.city.DoubleUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.VipBean

class VipAdapter : BaseQuickAdapter<VipBean, BaseViewHolder>(R.layout.app_item_vip) {
    var selectPosition = 0
    var visit = 0
    override fun convert(holder: BaseViewHolder, item: VipBean) {

        holder.setText(R.id.item_tv_name, item.cardName)
            .setText(R.id.item_tv_price, "¥${DoubleUtils.replace(item.cardPrice)}")
            .setText(R.id.item_tv_content, item.cardUnit)
            .setVisible(R.id.item_tv_tag, holder.adapterPosition == visit)

        holder.setBackgroundResource(
            R.id.content1, if (selectPosition == holder.adapterPosition) {
                R.drawable.app_bg_vip_menu_checked
            } else {
                R.drawable.app_bg_vip_menu_uncheck
            }
        )

        holder.itemView.setOnClickListener {
            if (getOnItemClickListener() != null) {
                getOnItemClickListener()?.onItemClick(this, it, holder.adapterPosition)
            }
            selectPosition = holder.adapterPosition
            notifyDataSetChanged()
        }
    }
}